package com.tf_cut.backend.person.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.Lists;
import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.common.pojo.Result;
import com.tf_cut.backend.person.service.PersonBillService;
import com.tf_cut.backend.person.service.PersonService;
import com.tf_cut.backend.person.vo.PersonBillAndConsigneeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/backend/admin/person/bill")
public class PersonBillController {

    @Autowired
    private PersonService personService;
    @Autowired
    private PersonBillService personBillService;

    @PostMapping("/list")
    public String queryPersonBillList(String json) {
        PersonBillAndConsigneeVo personBillAndConsigneeVo = JSON.parseObject(json, PersonBillAndConsigneeVo.class);
        Result<List<PersonBillAndConsigneeVo>> result;
        try {
            PageInfo<PersonBillAndConsigneeVo> personBillAndConsigneeVoList = personBillService.queryPersonBillList(personBillAndConsigneeVo);
            return JSON.toJSONString(personBillAndConsigneeVoList, SerializerFeature.WriteDateUseDateFormat);
        } catch (Exception e) {
            log.error("queryPersonBillList error:{}", e.getMessage(), e);
            result = Result.of(Lists.newArrayList());
            result.setMsg(e.getMessage());
            result.setFlag(false);
        }
        return JSON.toJSONString(result, SerializerFeature.WriteDateUseDateFormat);
    }

}
